import * as THREE from '../../build/three.module.js';
import {
  OrbitControls
} from '../../jsm/controls/OrbitControls.js'

// 场景
let scene = new THREE.Scene();

// 几何体
let geometry = new THREE.BufferGeometry();
let positionArray = new Float32Array([
  0, 0, 0,
  50, 0, 0,
  0, 100, 0,

  0, 0, 0,
  0, 0, 100,
  50, 0, 0
]);
geometry.attributes.position = new THREE.BufferAttribute(positionArray, 3);

// 几何法向量
let normalArray = new Float32Array([
  0, 0, 1,
  0, 0, 1,
  0, 0, 1,

  0, 1, 0,
  0, 1, 0,
  0, 1, 0
]);
geometry.attributes.normal = new THREE.BufferAttribute(normalArray, 3);

// 材质
let material = new THREE.MeshLambertMaterial({
  color: 0x0000ff,
  side: THREE.DoubleSide
});

// 网格对象
let mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);

// 光照
// 环境光
let ambient = new THREE.AmbientLight(0x444444);
scene.add(ambient);
// 点光源
let pointL = new THREE.PointLight(0xffffff);
pointL.position.set(0, 125, 200);
scene.add(pointL);

// 相机
let width = window.innerWidth,
    height = window.innerHeight,
    k = width / height,
    s = 200,
    camera = new THREE.OrthographicCamera(-s * k, s * k, s, -s, 1, 1000);
camera.position.set(400, 400, 400);
camera.lookAt(scene.position);

// 辅助线
let axesH = new THREE.AxesHelper(200);
scene.add(axesH);

// 渲染器
let renderer = new THREE.WebGLRenderer();
renderer.setSize(width, height);
renderer.setClearColor(0xeeeeee);
document.body.appendChild(renderer.domElement);

// 渲染函数
function render () {
  requestAnimationFrame(render);
  renderer.render(scene, camera);
};
render();

// 控制器
new OrbitControls(camera, renderer.domElement);